# This script runs a PSCAD file named Ferroresonance then Ferroresonance2, then Ferroresonance3 then quits. # Import configuration file and automation library import sys, os sys.path.append(r"C:\Program Files (x86)\PSCAD\Automation\Lib\mhrc") import automation.controller # Import other utilities from automation.utilities.file import File import win32com.client import shutil # Working directory (use current directory) # Assumes that this .py file is in the same folder as the .pscx file! #To run projects of any name replace Ferroresonance with the new project name, can run any number of files. working_dir = os.getcwd() + "\\" project_names = ['Ferroresonance','Ferroresonance2','Ferroresonance3'] # Sets the PSCAD application version pscad_version = 'PSCAD 4.6.1 (x64)' # Chooses the correct compiler for the .pscx file fortran_version = 'GFortran 4.6.2' fortran_ext = '.gf46' # Source and destination folders for output data src_folder = working_dir + fortran_ext dst_folder = working_dir + "output" # Get the Automation Controller that is used to launch PSCAD controller = automation.controller.Controller() # Launch PSCAD and silence all dialogue boxes pscad = controller.launch(pscad_version, options={'silence': True}) if pscad: try: # Check if Licensing Cetificate exists, on this computer pro = os.path.isfile(r"C:\Users\Public\Documents\Manitoba HVDC Research Centre\Licensing\Licenses\74.xml") # Existing certificate exists!, set PSCAD to use Certificate License if(pro): pscad.settings(cl_use_advanced='true') print("PSCAD is using a Certificate license!") # No Certificate exists, set PSCAD to use dongle License else: pscad.settings(cl_use_advanced='false') print("PSCAD is using a Dongle license!") # Set the compiler pscad.settings(fortran_version=fortran_version) # Load the projects for project_name in project_names: pscad.load([working_dir + project_name + ".pscx"]) project = pscad.project(project_name) #Calling the workspace from PSCAD. ws=pscad.workspace() #creating a simulation set called Batch in the pscad workspace ws.create_simulation_set("Batch") ss=ws.simulation_set("Batch") #loads the three projects into the simulation set for project_name in project_names: ss.add_tasks(project_name) # Get the "Main" canvas # main = project.user_canvas('Main') ss.run() pscad.quit() except: pass